import 'package:baseproject/model/carousel/carousel.dart';
import 'package:baseproject/view/base/webView.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class CarouselWidget extends StatefulWidget {
  CarouselWidget(Key key) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return CarouselWidgetState();
  }
}

class CarouselWidgetState extends State<CarouselWidget> {
  List<Carousel> _carouselList = new List();

  @override
  Widget build(BuildContext context) {
    return Swiper(
      itemBuilder: (BuildContext context, int index) {
        return new Image.network(
          _carouselList[index].picUrl,
          fit: BoxFit.fill,
        );
      },
      itemCount: _carouselList.length,
      //设置 new SwiperPagination() 展示默认分页指示器
      pagination: new SwiperPagination(),
      //设置 new SwiperControl() 展示默认分页按钮
      control: null,
      autoplay: true,
      onTap: (index) {
        print(_carouselList[index].url);
        Navigator.push(context,
            MaterialPageRoute(builder: (BuildContext context) {
          return WebView(
            url: _carouselList[index].url,
            title: _carouselList[index].title,
          );
        }));
      },
    );
  }

  void setCarouselList(List<Carousel> list) {
    setState(() {
      _carouselList = list;
    });
  }
}
